<template>
	<view class="ranking-container">
		<!-- 搜索框 -->
		<view class="search-bar">
			<uni-search-bar :focus="true" clearButton="none" cancelButton="none" placeholder="搜索排行榜"></uni-search-bar>
		</view>
		
		<!-- 排行榜头部 -->
		<view class="ranking-header">
			<text class="header-title">{{ rankings.title }}</text>
		</view>
		
		<!-- 排行榜列表 -->
		<view class="ranking-list">
			<view class="ranking-item" v-for="(item, index) in rankings.list" :key="index" @click="goToRankingDetail(item)">
				<!-- 排行榜封面 -->
				<view class="ranking-cover">
					<image :src="item.src" mode="aspectFill"></image>
					<view class="ranking-number">{{ index + 1 }}</view>
				</view>
				
				<!-- 排行榜信息 -->
				<view class="ranking-info">
					<text class="ranking-name">{{ item.name }}</text>
					<text class="ranking-description">{{ item.description }}</text>
					<view class="ranking-top-song">
						<uni-icons type="musical-notes" size="16" color="#666"></uni-icons>
						<text class="top-song-text">{{ item.topSong }}</text>
					</view>
					<view class="ranking-stats">
						<text class="ranking-count">播放量: {{ formatCount(item.count) }}</text>
					</view>
				</view>
				
				<!-- 箭头图标 -->
				<view class="ranking-arrow">
					<uni-icons type="arrowright" size="20" color="#999"></uni-icons>
				</view>
			</view>
		</view>
		
		<!-- 热门歌曲推荐 -->
		<view class="hot-songs-section">
			<uni-section :title="'热门歌曲'" type="circle"></uni-section>
			<view class="hot-songs-list">
				<view class="hot-song-item" v-for="(song, index) in hotSongs" :key="song.id">
					<!-- 排名 -->
					<view class="song-rank" :class="{ 'top-three': index < 3 }">
						{{ index + 1 }}
					</view>
					
					<!-- 歌曲信息 -->
					<view class="song-info">
						<text class="song-name">{{ song.name }}</text>
						<text class="song-author">{{ song.author }}</text>
					</view>
					
					<!-- 播放按钮 -->
					<view class="song-play" @click.stop="playSong(song)">
						<uni-icons type="play" size="24" color="#00c273"></uni-icons>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// 导入mock数据
	import { rankings, audioList } from '../../commons/mock.js'

export default {
	name: 'RankingPage',
	data() {
		return {
			rankings,
			// 从audioList中获取热门歌曲（这里简化处理，实际可以根据播放量排序）
			hotSongs: audioList.slice(0, 10)
		}
	},
	methods: {
		// 格式化播放量
		formatCount(count) {
			if (count >= 10000) {
				return (count / 10000).toFixed(1) + '万'
			}
			return count
		},
		
		// 跳转到排行榜详情
		goToRankingDetail(item) {
			// 这里可以跳转到具体排行榜详情页，目前先显示提示
			uni.showToast({
				title: '即将进入' + item.name,
				icon: 'none'
			})
		},
		
		// 播放歌曲
		playSong(song) {
			uni.navigateTo({
				url: '../play/play?songId=' + song.id
			})
		}
	}
}
</script>

<style lang="scss">
	.ranking-container {
		background-color: #f5f5f5;
		min-height: 100vh;
	}
	
	// 搜索栏样式
	.search-bar {
		padding: 10rpx 20rpx;
		background-color: #00c273;
	}
	
	// 排行榜头部
	.ranking-header {
		padding: 20rpx 30rpx;
		background-color: #fff;
		border-bottom: 1rpx solid #eee;
	}
	
	.header-title {
		font-size: 40rpx;
		font-weight: bold;
		color: #333;
	}
	
	// 排行榜列表
	.ranking-list {
		margin: 20rpx;
		background-color: #fff;
		border-radius: 10rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}
	
	// 排行榜项
	.ranking-item {
		display: flex;
		align-items: center;
		padding: 20rpx 30rpx;
		border-bottom: 1rpx solid #f0f0f0;
		&:last-child {
			border-bottom: none;
		}
		&:active {
			background-color: #f5f5f5;
		}
	}
	
	// 排行榜封面
	.ranking-cover {
		position: relative;
		width: 160rpx;
		height: 160rpx;
		margin-right: 20rpx;
		border-radius: 8rpx;
		overflow: hidden;
		
		image {
			width: 100%;
			height: 100%;
		}
		
		.ranking-number {
			position: absolute;
			top: 0;
			left: 0;
			width: 40rpx;
			height: 40rpx;
			background-color: rgba(0, 0, 0, 0.6);
			color: #fff;
			font-size: 24rpx;
			font-weight: bold;
			display: flex;
			align-items: center;
			justify-content: center;
		}
	}
	
	// 排行榜信息
	.ranking-info {
		flex: 1;
		justify-content: center;
	}
	
	.ranking-name {
		display: block;
		font-size: 34rpx;
		font-weight: bold;
		color: #333;
		margin-bottom: 8rpx;
	}
	
	.ranking-description {
		display: block;
		font-size: 28rpx;
		color: #666;
		margin-bottom: 12rpx;
	}
	
	.ranking-top-song {
		display: flex;
		align-items: center;
		margin-bottom: 8rpx;
	}
	
	.top-song-text {
		margin-left: 8rpx;
		font-size: 28rpx;
		color: #999;
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}
	
	.ranking-stats {
		font-size: 26rpx;
		color: #ff6b6b;
	}
	
	// 箭头图标
	.ranking-arrow {
		margin-left: 20rpx;
	}
	
	// 热门歌曲区域
	.hot-songs-section {
		margin: 20rpx;
		background-color: #fff;
		border-radius: 10rpx;
		overflow: hidden;
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}
	
	// 热门歌曲列表
	.hot-songs-list {
		padding: 20rpx 30rpx;
	}
	
	// 热门歌曲项
	.hot-song-item {
		display: flex;
		align-items: center;
		padding: 20rpx 0;
		border-bottom: 1rpx solid #f0f0f0;
		&:last-child {
			border-bottom: none;
		}
	}
	
	// 歌曲排名
	.song-rank {
		width: 40rpx;
		height: 40rpx;
		font-size: 28rpx;
		font-weight: bold;
		color: #999;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 20rpx;
	}
	
	.top-three {
		background-color: #ff6b6b;
		color: #fff;
		border-radius: 50%;
	}
	
	// 歌曲信息
	.song-info {
		flex: 1;
	}
	
	.song-name {
		display: block;
		font-size: 32rpx;
		color: #333;
		margin-bottom: 8rpx;
	}
	
	.song-author {
		display: block;
		font-size: 28rpx;
		color: #999;
	}
	
	// 播放按钮
	.song-play {
		margin-left: 20rpx;
		padding: 10rpx;
	}
</style>